package cn.tedu.rabbitmqboot.m2;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 消费者自动启动,注册成为消费者,自动监听队列中的消息,不需要手动调用
 * 写法1.@RabbitListener 在类上注解需要@RabbitHandler配合指定处理消息的方法
 * 写法2.直接加在方法上
 */
@Component
public class Consumer {
    @RabbitListener(queues = "task_queue")
    public void receive1(String msg){
       System.out.println("消费者1,收到消息"+msg);
    }

    @RabbitListener(queues = "task_queue")
    public void receive2(String msg){
       System.out.println("消费者2,收到消息"+msg);
    }


}
